import { Promise } from 'es6-promise'
import  { mapGetters, mapActions }  from 'vuex'

const mixin = {

    data() {
        return {
            show_modal_report:false,
            show_modal_bind_card:false,
            modalReportText:'',
            modalReportTips:''
        }
    },
    computed:{
        ...mapGetters([
            'localInfo'
        ]),
        reportInfo(){
            return this.localInfo.reportInfo
        },
    },
    methods: {
        // actions
        ...mapActions([
            'setReportInfo'
        ]),
        goReport(){
            this.$router.push({
                name:'user-credit-report-index'
            })
        },
    },
    created(){
        if(!this.reportInfo){
            this.setReportInfo()
            .then(result=>{
                if(!_.isEmpty(this.reportInfo.bankcard)){
                    if(this.reportInfo.creditReport.status == 'OK') return
                    if(this.reportInfo.creditReport.status == 'NO'){
                        this.modalReportText='去完成认证'
                        this.modalReportTips='您尚未完成信用报告认证，7日内前往“账户-我的”进行补充完善。如放弃认证，7日内联系客服退款。'
                    }
                    if(this.reportInfo.creditReport.status == 'USELESS'){
                        this.modalReportText='去重新认证'
                        this.modalReportTips='信用报告已经过期失效，需重新认证后才能借款/出借。'
                    }

                    this.show_modal_report = true
                    this.reportCallback && this.reportCallback()
                }
            })
            .catch(error => {
                console.error(error)
            })
        }
        else{
            if(!_.isEmpty(this.reportInfo.bankcard)){
                if(this.reportInfo.CREDIT.state == 'SUCCESS') return
                this.show_modal_report = true
                this.modalReportText='您尚未完成信用报告认证，7日内前往“账户-我的”进行补充完善。如放弃认证，7日内联系客服退款。'
                this.modalReportTips='去完成认证'
                this.reportCallback && this.reportCallback()
            }
        }
    }
}

export default mixin